package com.feicheng.controller.system;


import com.feicheng.common.constant.Constant;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.persistence.entity.Role;
import com.feicheng.service.IFSystemService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cailongyang
 * @since 2021-12-02
 */
@RestController("/admin/role")
@RequestMapping("/admin/role")
public class RoleController {

    @Resource(name="system-admin-service")
    IFSystemService iFSystemService;

    @DeleteMapping("/info")
    public ResultInfo deleteRole(Integer roleId) {
        return iFSystemService.deleteUser(roleId);
    }

    @PostMapping("/info")
    @Transactional
    public ResultInfo addRole(Role role, String permissions) {
        return iFSystemService.addRole(role, permissions);
    }

    @PutMapping("/info")
    @Transactional
    public ResultInfo updateRole(Role role, String permissions) {
        return iFSystemService.updateRole(role, permissions);
    }

    @GetMapping("/info")
    public ResultInfo getRoleById(Integer roleId) {
        return iFSystemService.getRoleById(roleId);
    }

    @GetMapping("/all")
    public ResultInfo all() {
        return iFSystemService.allRoles(true);
    }

    @GetMapping("/list")
    public ResultInfo list(
            String roleName,
            Boolean status,
            @RequestParam(defaultValue="1") Integer currentPage,
            @RequestParam(defaultValue="10")Integer pageSize
    ) {
        return iFSystemService.selectRoles(roleName, status, currentPage, pageSize);
    }

}
